package com.space.myapollo;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class MyDataSourceConfig {

	@Primary
	@Bean(name="h2DataSourceProperties")
	@ConfigurationProperties(prefix = "spring.datasource")
	public DataSourceProperties h2DataSourceProperties() {
		return new DataSourceProperties();
	}

	/**
	 * 主数据源 H2 数据源
	 * @param h2DataSource
	 * @return
	 */
	@Primary
	@Bean(name = "h2DataSource")
	public DataSource dsyygjDataSource(
			@Qualifier("h2DataSourceProperties") DataSourceProperties dataSourceProperties) {
		return dataSourceProperties.initializeDataSourceBuilder().build();
	}
}
